package com.kehutong.crm.admin;

import com.kehutong.crm.entity.ForecastStatistics;
import com.kehutong.crm.enums.DemandForecastTypeEnum;
import com.kehutong.crm.service.ForecastStatisticsService;
import org.coraframework.inject.Inject;
import org.coraframework.mvc.MvcAction;
import org.coraframework.mvc.http.ReqMapping;
import org.coraframework.mvc.http.result.Result;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 客户标签控制器
 *
 * @author wupengfei
 */
@MvcAction
@ReqMapping("/admin/crm/forecast/statistics")
public class ForecastStatisticsController {

    @Inject
    private ForecastStatisticsService forecastStatisticsService;

    @ReqMapping("/rearrange")
    public Object rearrange(String id) throws Exception {
        return forecastStatisticsService.rearrange(id);
    }

    @ReqMapping("/list")
    public Object list() {
        List<ForecastStatistics> result = forecastStatisticsService.list();
        return Result.success(result);
    }

    @ReqMapping("/calc")
    public Object calc() {
        forecastStatisticsService.statistics();
        return Result.success();
    }

    @ReqMapping("/type")
    public Object type() {
        Map<String, DemandForecastTypeEnum> enumMap = DemandForecastTypeEnum.getEnumMap();
        Map<String, String> result = new HashMap<>();
        for (Map.Entry<String, DemandForecastTypeEnum> entry : enumMap.entrySet()) {
            result.put(entry.getKey(), entry.getValue().getName());
        }
        return Result.success(result);
    }
}
